import request from "@/utils/request";
import {reactive} from "vue";

const BASE_URL = "/api/admin";


const ArticleAPI = {
  updateArticle(article: ArticleInfo) {
    return request<any, any>({
      url: `${BASE_URL}/article`,
      data: article,
      method: "put",
    });
  },

  deleteArticle(article_id:number) {
    return request<any, any>({
      url: `${BASE_URL}/article`,
      params: {article_id},
      method: "delete",
    });
  },
  updateArticleStatus(article_id:number, newStatus:number) {
    return request<any, any>({
      url: `${BASE_URL}/articleStatus`,
      params: {article_id, newStatus},
      method: "put",
    });
  },

  addArticle(article: ArticleInfo) {
    return request<any, any>({
      url: `${BASE_URL}/article`,
      data: article,
      method: "post",
    });
  },
  /**
   * 获取分页文章
   */
  fetchArticle(query: QueryMultiArticle) {
    return request<any, ArticlePageData>({
      url: `${BASE_URL}/articleList`,
      params: query,
      method: "get",
    });
  },

};

export default ArticleAPI;

export interface QueryMultiArticle{
  page?: number;
  pageSize?: number;
  title: string | undefined;
  status: undefined | boolean ;
  category_id: number | undefined;
  tag_ids: number[] | undefined;
}


export interface ArticlePageData {
  article: ArticleInfo[];
  count: number;
}

export interface ArticleInfo {
  article_id:number;
  title: string;
  content: string;
  publish_date: number;
  intro: string;
  views: number;
  status: boolean | number;
  cover: string;
  tag_ids: string | number[];
  is_admin: boolean;
  category_id: number;
  category_name: string;
  add_date: number;
  update_date: number;
  user_id: number;
  admin_id: number;
  good_count: number;
}
